#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>
#include<algorithm>
using namespace std;
int n = 0;
int arr[5001] = { 0 };
struct pole{
	int l, w;
}a[5001];
bool pole_cmp(pole s1, pole s2)
{
	if (s1.l == s2.l) {
		return s1.w > s2.w;
	}
	return s1.l > s2.l;
}
int main()
{
	int count = 0,i = 0;
	cin >> n;
	for (i = 0; i < n; i++) 
		cin >> a[i].l >> a[i].w;
	sort(a, a + n, pole_cmp);
	arr[0] = a[0].w;
	for (i = 1; i < n; i++)
	{
		if (arr[count] < a[i].w) 
		{
			arr[++count] = a[i].w;
		}
		else 
		{
			*lower_bound(arr, arr + count, a[i].w) = a[i].w;
		}
	}
	count += 1;
	cout << count << endl;
	return 0;
}